home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Sample.bin / Utility.java < prev    next >
Text File  |  1998-09-15  |  4KB  |  112 lines

  1. /*
  2.  * @(#)Utility.java     1.1 98/06/16
  3.  *
  4.  * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved
  5.  * (C) Copyright IBM Corp. 1996 - All Rights Reserved
  6.  *
  7.  * Portions copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved.
  8.  *
  9.  *   The original version of this source code and documentation is copyrighted
  10.  * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
  11.  * materials are provided under terms of a License Agreement between Taligent
  12.  * and Sun. This technology is protected by multiple US and International
  13.  * patents. This notice and attribution to Taligent may not be removed.
  14.  *   Taligent is a registered trademark of Taligent, Inc.
  15.  *
  16.  * Permission to use, copy, modify, and distribute this software
  17.  * and its documentation for NON-COMMERCIAL purposes and without
  18.  * fee is hereby granted provided that this copyright notice
  19.  * appears in all copies. Please refer to the file "copyright.html"
  20.  * for further important copyright and licensing information.
  21.  *
  22.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  23.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  24.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  25.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  26.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  27.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  28.  *
  29.  */
  30.  
  31. import java.awt.*;
  32. import java.lang.*;
  33. import java.util.*;
  34.  
  35. public class Utility
  36. {
  37.     public static final Font titleFont = new Font("TimesRoman",Font.BOLD,18);
  38.     public static final Font labelFont = new Font("TimesRoman",Font.BOLD,14);
  39.     public static final Font choiceFont = new Font("Helvetica",Font.BOLD,12);
  40.     public static final Font editFont = new Font("Helvetica",Font.PLAIN,14);
  41.     public static final Font creditFont = new Font("Helvetica",Font.PLAIN,10);
  42.  
  43.     /**
  44.     Provides easy way to use basic functions of GridBagLayout, without
  45.     the complications. After building a panel, and inserting all the
  46.     * subcomponents, call this to lay it out in the desired number of columns.
  47.     */
  48.     public static void fixGrid(Container cont, int columns) {
  49.         GridBagLayout gridbag = new GridBagLayout();
  50.         cont.setLayout(gridbag);
  51.  
  52.         GridBagConstraints c = new GridBagConstraints();
  53.         c.fill = GridBagConstraints.VERTICAL;
  54.         c.weightx = 1.0;
  55.         c.insets = new Insets(2,2,2,2);
  56.  
  57.         Component[] components = cont.getComponents();
  58.         for (int i = 0; i < components.length; ++i) {
  59.             int colNumber = i%columns;
  60.             c.gridwidth = 1;    // default
  61.             if ((i%columns) == columns - 1)
  62.                 c.gridwidth = GridBagConstraints.REMAINDER;    // last in grid
  63.             if (components[i] instanceof Label) {
  64.                 switch (((Label)components[i]).getAlignment()) {
  65.                 case Label.CENTER: c.anchor = GridBagConstraints.CENTER; break;
  66.                 case Label.LEFT: c.anchor = GridBagConstraints.WEST; break;
  67.                 case Label.RIGHT: c.anchor = GridBagConstraints.EAST; break;
  68.                 }
  69.             }
  70.             gridbag.setConstraints(components[i], c);
  71.         }
  72.  
  73.     }
  74.  
  75.     /**
  76.     Provides easy way to change the spacing around an object in a GridBagLayout.
  77.     Call AFTER fixGridBag, passing in the container, the component, and the
  78.     new insets.
  79.     */
  80.     public static void setInsets(Container cont, Component comp, Insets insets) {
  81.         GridBagLayout gbl = (GridBagLayout)cont.getLayout();
  82.         GridBagConstraints g = gbl.getConstraints(comp);
  83.         g.insets = insets;
  84.         gbl.setConstraints(comp,g);
  85.     }
  86.  
  87.  
  88.     // to avoid goofy updates and misplaced cursors
  89.     public static void setText(TextComponent area, String newText) {
  90.         String foo = area.getText();
  91.         if (foo.equals(newText)) return;
  92.         area.setText(newText);
  93.     }
  94.     /**
  95.      * Get the G7 locale list for demos.
  96.      */
  97.     public static Locale[] getG7Locales() {
  98.         return localeList;
  99.     }
  100.     private static Locale[] localeList = {
  101.         new Locale("DA", "DK", ""),
  102.         new Locale("EN", "US", ""),
  103.         new Locale("EN", "GB", ""),
  104.         new Locale("EN", "CA", ""),
  105.         new Locale("FR", "FR", ""),
  106.         new Locale("FR", "CA", ""),
  107.         new Locale("DE", "DE", ""),
  108.         new Locale("IT", "IT", ""),
  109.     new Locale("JA", "JP", ""),
  110.     };
  111. }
  112.